import React, { Component } from 'react'
import usp from 'url-search-params';
const DetailDatas = [
    {id: '01', data: '消息一的内容'},
    {id: '02', data: '消息二的内容'},
    {id: '03', data: '消息三的内容'}
]
export default class Detail extends Component {
    render() {
        // 使用params传递参数
        // const {id,title} = this.props.match.params
        // 接受search参数
        const {search} = this.props.location
        const uspData = new usp(search.slice(1))
        const id = uspData.get('id')
        const title= uspData.get('title')
        // 使用state传递参数
        // const {id,title} = this.props.location.state || {}
        const findResult = DetailDatas.find(DetailData=>DetailData.id === id)||{}
        return (
            <div>
                <ul>
                    <li>ID:{id}</li>
                    <li>TITLE:{title}</li>
                    <li>DATA:{findResult.data}</li>
                </ul>
            </div>
        )
    }
}
